﻿
namespace UserDefinedForms.Windows.Forms
{
	/// <summary>
	/// abstract FormControl typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class FormControlDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<FormControlDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.FormControl _currentFormControl = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxFormControlDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxFormControlErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxFormControlBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ControlId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxControlIdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Name property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNameDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the ControlTypeId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxControlTypeIdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ToolTipText property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxToolTipTextDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Border property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxBorderDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Top property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxTopDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Left property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxLeftDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Width property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxWidthDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Height property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxHeightDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Font property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxFontDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DefaultValue property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDefaultValueDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Visible property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxVisibleDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Enable property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxEnableDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IsSummaryField property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxIsSummaryFieldDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IsCommon property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxIsCommonDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IsCode property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxIsCodeDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IsLayout property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxIsLayoutDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the ComponentId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxComponentIdDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the FormId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxFormIdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the FormType property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxFormTypeDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Status property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxStatusDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Description property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDescriptionDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.FormControl> _ComponentIdList;
		
		/// <summary> 
		/// The list of selectable FormControl
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.FormControl> ComponentIdList
		{
			get {return this._ComponentIdList;}
			set 
			{
				this._ComponentIdList = value;
				this.uxComponentIdDataGridViewColumn.DataSource = null;
				this.uxComponentIdDataGridViewColumn.DataSource = this._ComponentIdList;
			}
		}
		
		private bool _allowNewItemInComponentIdList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of FormControl
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInComponentIdList
		{
			get { return _allowNewItemInComponentIdList;}
			set
			{
				this._allowNewItemInComponentIdList = value;
				this.uxComponentIdDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.DesignForm> _FormIdList;
		
		/// <summary> 
		/// The list of selectable DesignForm
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.DesignForm> FormIdList
		{
			get {return this._FormIdList;}
			set 
			{
				this._FormIdList = value;
				this.uxFormIdDataGridViewColumn.DataSource = null;
				this.uxFormIdDataGridViewColumn.DataSource = this._FormIdList;
			}
		}
		
		private bool _allowNewItemInFormIdList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of DesignForm
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInFormIdList
		{
			get { return _allowNewItemInFormIdList;}
			set
			{
				this._allowNewItemInFormIdList = value;
				this.uxFormIdDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.ControlType> _ControlTypeIdList;
		
		/// <summary> 
		/// The list of selectable ControlType
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.ControlType> ControlTypeIdList
		{
			get {return this._ControlTypeIdList;}
			set 
			{
				this._ControlTypeIdList = value;
				this.uxControlTypeIdDataGridViewColumn.DataSource = null;
				this.uxControlTypeIdDataGridViewColumn.DataSource = this._ControlTypeIdList;
			}
		}
		
		private bool _allowNewItemInControlTypeIdList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of ControlType
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInControlTypeIdList
		{
			get { return _allowNewItemInControlTypeIdList;}
			set
			{
				this._allowNewItemInControlTypeIdList = value;
				this.uxControlTypeIdDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.FormControl> _FormControlList;
				
		/// <summary> 
		/// The list of FormControl to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.FormControl> FormControlList
		{
			get {return this._FormControlList;}
			set
			{
				this._FormControlList = value;
				this.uxFormControlBindingSource.DataSource = null;
				this.uxFormControlBindingSource.DataSource = value;
				this.uxFormControlDataGridView.DataSource = null;
				this.uxFormControlDataGridView.DataSource = this.uxFormControlBindingSource;				
				//this.uxFormControlBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxFormControlBindingSource_ListChanged);
				this.uxFormControlBindingSource.CurrentItemChanged += new System.EventHandler(OnFormControlBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnFormControlBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentFormControl = uxFormControlBindingSource.Current as Entities.FormControl;
			
			if (_currentFormControl != null)
			{
				_currentFormControl.Validate();
			}
			//_FormControl.Validate();
			OnCurrentEntityChanged();
		}

		//void uxFormControlBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <see cref="Entities.FormControl"/> instance.
		/// </summary>
		public Entities.FormControl SelectedFormControl
		{
			get {return this._currentFormControl;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxFormControlDataGridView.VirtualMode;}
			set
			{
				this.uxFormControlDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxFormControlDataGridView.AllowUserToAddRows;}
			set {this.uxFormControlDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxFormControlDataGridView.AllowUserToDeleteRows;}
			set {this.uxFormControlDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <see cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxFormControlDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxFormControlDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="FormControlDataGridViewBase"/> class.
		/// </summary>
		public FormControlDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxFormControlDataGridView = new System.Windows.Forms.DataGridView();
			this.uxFormControlBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxFormControlErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxControlIdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxNameDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxControlTypeIdDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxToolTipTextDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxBorderDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			this.uxTopDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxLeftDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxWidthDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxHeightDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxFontDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDefaultValueDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxVisibleDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			this.uxEnableDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			this.uxIsSummaryFieldDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			this.uxIsCommonDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			this.uxIsCodeDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			this.uxIsLayoutDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			this.uxComponentIdDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxFormIdDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxFormTypeDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxStatusDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDescriptionDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			//this.uxComponentIdBindingSource = new FormControlBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxComponentIdBindingSource)).BeginInit();
			//this.uxFormIdBindingSource = new DesignFormBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxFormIdBindingSource)).BeginInit();
			//this.uxControlTypeIdBindingSource = new ControlTypeBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxControlTypeIdBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormControlDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormControlBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormControlErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxFormControlErrorProvider
			// 
			this.uxFormControlErrorProvider.ContainerControl = this;
			this.uxFormControlErrorProvider.DataSource = this.uxFormControlBindingSource;						
			// 
			// uxFormControlDataGridView
			// 
			this.uxFormControlDataGridView.AutoGenerateColumns = false;
			this.uxFormControlDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxFormControlDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxControlIdDataGridViewColumn,
		this.uxNameDataGridViewColumn,
		this.uxControlTypeIdDataGridViewColumn,
		this.uxToolTipTextDataGridViewColumn,
		this.uxBorderDataGridViewColumn,
		this.uxTopDataGridViewColumn,
		this.uxLeftDataGridViewColumn,
		this.uxWidthDataGridViewColumn,
		this.uxHeightDataGridViewColumn,
		this.uxFontDataGridViewColumn,
		this.uxDefaultValueDataGridViewColumn,
		this.uxVisibleDataGridViewColumn,
		this.uxEnableDataGridViewColumn,
		this.uxIsSummaryFieldDataGridViewColumn,
		this.uxIsCommonDataGridViewColumn,
		this.uxIsCodeDataGridViewColumn,
		this.uxIsLayoutDataGridViewColumn,
		this.uxComponentIdDataGridViewColumn,
		this.uxFormIdDataGridViewColumn,
		this.uxFormTypeDataGridViewColumn,
		this.uxStatusDataGridViewColumn,
		this.uxDescriptionDataGridViewColumn			});
			this.uxFormControlDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxFormControlDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxFormControlDataGridView.Name = "uxFormControlDataGridView";
			this.uxFormControlDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxFormControlDataGridView.TabIndex = 0;	
			this.uxFormControlDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxFormControlDataGridView.EnableHeadersVisualStyles = false;
			this.uxFormControlDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnFormControlDataGridViewDataError);
			this.uxFormControlDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnFormControlDataGridViewCellValueNeeded);
			this.uxFormControlDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnFormControlDataGridViewCellValuePushed);
			
			//
			// uxControlIdDataGridViewColumn
			//
			this.uxControlIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxControlIdDataGridViewColumn.DataPropertyName = "ControlId";
			this.uxControlIdDataGridViewColumn.HeaderText = "ControlId";
			this.uxControlIdDataGridViewColumn.Name = "uxControlIdDataGridViewColumn";
			this.uxControlIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxControlIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxControlIdDataGridViewColumn.ReadOnly = true;		
			//
			// uxNameDataGridViewColumn
			//
			this.uxNameDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNameDataGridViewColumn.DataPropertyName = "Name";
			this.uxNameDataGridViewColumn.HeaderText = "Name";
			this.uxNameDataGridViewColumn.Name = "uxNameDataGridViewColumn";
			this.uxNameDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNameDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNameDataGridViewColumn.ReadOnly = false;		
			//
			// uxControlTypeIdDataGridViewColumn
			//
			this.uxControlTypeIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxControlTypeIdDataGridViewColumn.DataPropertyName = "ControlTypeId";
			this.uxControlTypeIdDataGridViewColumn.HeaderText = "ControlTypeId";
			this.uxControlTypeIdDataGridViewColumn.Name = "uxControlTypeIdDataGridViewColumn";
			this.uxControlTypeIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxControlTypeIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxControlTypeIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxToolTipTextDataGridViewColumn
			//
			this.uxToolTipTextDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxToolTipTextDataGridViewColumn.DataPropertyName = "ToolTipText";
			this.uxToolTipTextDataGridViewColumn.HeaderText = "ToolTipText";
			this.uxToolTipTextDataGridViewColumn.Name = "uxToolTipTextDataGridViewColumn";
			this.uxToolTipTextDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxToolTipTextDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxToolTipTextDataGridViewColumn.ReadOnly = false;		
			//
			// uxBorderDataGridViewColumn
			//
			this.uxBorderDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxBorderDataGridViewColumn.DataPropertyName = "Border";
			this.uxBorderDataGridViewColumn.HeaderText = "Border";
			this.uxBorderDataGridViewColumn.Name = "uxBorderDataGridViewColumn";
			this.uxBorderDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxBorderDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxBorderDataGridViewColumn.ReadOnly = false;		
			//
			// uxTopDataGridViewColumn
			//
			this.uxTopDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxTopDataGridViewColumn.DataPropertyName = "Top";
			this.uxTopDataGridViewColumn.HeaderText = "Top";
			this.uxTopDataGridViewColumn.Name = "uxTopDataGridViewColumn";
			this.uxTopDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxTopDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxTopDataGridViewColumn.ReadOnly = false;		
			//
			// uxLeftDataGridViewColumn
			//
			this.uxLeftDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxLeftDataGridViewColumn.DataPropertyName = "Left";
			this.uxLeftDataGridViewColumn.HeaderText = "Left";
			this.uxLeftDataGridViewColumn.Name = "uxLeftDataGridViewColumn";
			this.uxLeftDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxLeftDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxLeftDataGridViewColumn.ReadOnly = false;		
			//
			// uxWidthDataGridViewColumn
			//
			this.uxWidthDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxWidthDataGridViewColumn.DataPropertyName = "Width";
			this.uxWidthDataGridViewColumn.HeaderText = "Width";
			this.uxWidthDataGridViewColumn.Name = "uxWidthDataGridViewColumn";
			this.uxWidthDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxWidthDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxWidthDataGridViewColumn.ReadOnly = false;		
			//
			// uxHeightDataGridViewColumn
			//
			this.uxHeightDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxHeightDataGridViewColumn.DataPropertyName = "Height";
			this.uxHeightDataGridViewColumn.HeaderText = "Height";
			this.uxHeightDataGridViewColumn.Name = "uxHeightDataGridViewColumn";
			this.uxHeightDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxHeightDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxHeightDataGridViewColumn.ReadOnly = false;		
			//
			// uxFontDataGridViewColumn
			//
			this.uxFontDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxFontDataGridViewColumn.DataPropertyName = "Font";
			this.uxFontDataGridViewColumn.HeaderText = "Font";
			this.uxFontDataGridViewColumn.Name = "uxFontDataGridViewColumn";
			this.uxFontDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxFontDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxFontDataGridViewColumn.ReadOnly = false;		
			//
			// uxDefaultValueDataGridViewColumn
			//
			this.uxDefaultValueDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDefaultValueDataGridViewColumn.DataPropertyName = "DefaultValue";
			this.uxDefaultValueDataGridViewColumn.HeaderText = "DefaultValue";
			this.uxDefaultValueDataGridViewColumn.Name = "uxDefaultValueDataGridViewColumn";
			this.uxDefaultValueDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDefaultValueDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDefaultValueDataGridViewColumn.ReadOnly = false;		
			//
			// uxVisibleDataGridViewColumn
			//
			this.uxVisibleDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxVisibleDataGridViewColumn.DataPropertyName = "Visible";
			this.uxVisibleDataGridViewColumn.HeaderText = "Visible";
			this.uxVisibleDataGridViewColumn.Name = "uxVisibleDataGridViewColumn";
			this.uxVisibleDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxVisibleDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxVisibleDataGridViewColumn.ReadOnly = false;		
			//
			// uxEnableDataGridViewColumn
			//
			this.uxEnableDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxEnableDataGridViewColumn.DataPropertyName = "Enable";
			this.uxEnableDataGridViewColumn.HeaderText = "Enable";
			this.uxEnableDataGridViewColumn.Name = "uxEnableDataGridViewColumn";
			this.uxEnableDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxEnableDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxEnableDataGridViewColumn.ReadOnly = false;		
			//
			// uxIsSummaryFieldDataGridViewColumn
			//
			this.uxIsSummaryFieldDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIsSummaryFieldDataGridViewColumn.DataPropertyName = "IsSummaryField";
			this.uxIsSummaryFieldDataGridViewColumn.HeaderText = "IsSummaryField";
			this.uxIsSummaryFieldDataGridViewColumn.Name = "uxIsSummaryFieldDataGridViewColumn";
			this.uxIsSummaryFieldDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIsSummaryFieldDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIsSummaryFieldDataGridViewColumn.ReadOnly = false;		
			//
			// uxIsCommonDataGridViewColumn
			//
			this.uxIsCommonDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIsCommonDataGridViewColumn.DataPropertyName = "IsCommon";
			this.uxIsCommonDataGridViewColumn.HeaderText = "IsCommon";
			this.uxIsCommonDataGridViewColumn.Name = "uxIsCommonDataGridViewColumn";
			this.uxIsCommonDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIsCommonDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIsCommonDataGridViewColumn.ReadOnly = false;		
			//
			// uxIsCodeDataGridViewColumn
			//
			this.uxIsCodeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIsCodeDataGridViewColumn.DataPropertyName = "IsCode";
			this.uxIsCodeDataGridViewColumn.HeaderText = "IsCode";
			this.uxIsCodeDataGridViewColumn.Name = "uxIsCodeDataGridViewColumn";
			this.uxIsCodeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIsCodeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIsCodeDataGridViewColumn.ReadOnly = false;		
			//
			// uxIsLayoutDataGridViewColumn
			//
			this.uxIsLayoutDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIsLayoutDataGridViewColumn.DataPropertyName = "IsLayout";
			this.uxIsLayoutDataGridViewColumn.HeaderText = "IsLayout";
			this.uxIsLayoutDataGridViewColumn.Name = "uxIsLayoutDataGridViewColumn";
			this.uxIsLayoutDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIsLayoutDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIsLayoutDataGridViewColumn.ReadOnly = false;		
			//
			// uxComponentIdDataGridViewColumn
			//
			this.uxComponentIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxComponentIdDataGridViewColumn.DataPropertyName = "ComponentId";
			this.uxComponentIdDataGridViewColumn.HeaderText = "ComponentId";
			this.uxComponentIdDataGridViewColumn.Name = "uxComponentIdDataGridViewColumn";
			this.uxComponentIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxComponentIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxComponentIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxFormIdDataGridViewColumn
			//
			this.uxFormIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxFormIdDataGridViewColumn.DataPropertyName = "FormId";
			this.uxFormIdDataGridViewColumn.HeaderText = "FormId";
			this.uxFormIdDataGridViewColumn.Name = "uxFormIdDataGridViewColumn";
			this.uxFormIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxFormIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxFormIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxFormTypeDataGridViewColumn
			//
			this.uxFormTypeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxFormTypeDataGridViewColumn.DataPropertyName = "FormType";
			this.uxFormTypeDataGridViewColumn.HeaderText = "FormType";
			this.uxFormTypeDataGridViewColumn.Name = "uxFormTypeDataGridViewColumn";
			this.uxFormTypeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxFormTypeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxFormTypeDataGridViewColumn.ReadOnly = false;		
			//
			// uxStatusDataGridViewColumn
			//
			this.uxStatusDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxStatusDataGridViewColumn.DataPropertyName = "Status";
			this.uxStatusDataGridViewColumn.HeaderText = "Status";
			this.uxStatusDataGridViewColumn.Name = "uxStatusDataGridViewColumn";
			this.uxStatusDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxStatusDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxStatusDataGridViewColumn.ReadOnly = false;		
			//
			// uxDescriptionDataGridViewColumn
			//
			this.uxDescriptionDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDescriptionDataGridViewColumn.DataPropertyName = "Description";
			this.uxDescriptionDataGridViewColumn.HeaderText = "Description";
			this.uxDescriptionDataGridViewColumn.Name = "uxDescriptionDataGridViewColumn";
			this.uxDescriptionDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDescriptionDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDescriptionDataGridViewColumn.ReadOnly = false;		
			//
			// uxComponentIdDataGridViewColumn
			//				
			this.uxComponentIdDataGridViewColumn.DisplayMember = "Name";	
			this.uxComponentIdDataGridViewColumn.ValueMember = "ControlId";	
			this.uxComponentIdDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxComponentIdDataGridViewColumn.DataSource = uxComponentIdBindingSource;				
				
			//
			// uxFormIdDataGridViewColumn
			//				
			this.uxFormIdDataGridViewColumn.DisplayMember = "Name";	
			this.uxFormIdDataGridViewColumn.ValueMember = "FormId";	
			this.uxFormIdDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxFormIdDataGridViewColumn.DataSource = uxFormIdBindingSource;				
				
			//
			// uxControlTypeIdDataGridViewColumn
			//				
			this.uxControlTypeIdDataGridViewColumn.DisplayMember = "Name";	
			this.uxControlTypeIdDataGridViewColumn.ValueMember = "ControlTypeId";	
			this.uxControlTypeIdDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxControlTypeIdDataGridViewColumn.DataSource = uxControlTypeIdBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxFormControlDataGridView);
			this.Name = "FormControlDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxComponentIdBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxFormIdBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxControlTypeIdBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormControlErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormControlDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxFormControlBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				FormControlDataGridViewEventArgs args = new FormControlDataGridViewEventArgs();
				args.FormControl = _currentFormControl;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class FormControlDataGridViewEventArgs : System.EventArgs
		{
			private Entities.FormControl	_FormControl;
	
			/// <summary>
			/// the  Entities.FormControl instance.
			/// </summary>
			public Entities.FormControl FormControl
			{
				get { return _FormControl; }
				set { _FormControl = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxFormControlDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnFormControlDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxFormControlDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnFormControlDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxFormControlDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxControlIdDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].ControlId;
						break;
					case "uxNameDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Name;
						break;
					case "uxControlTypeIdDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].ControlTypeId;
						break;
					case "uxToolTipTextDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].ToolTipText;
						break;
					case "uxBorderDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Border;
						break;
					case "uxTopDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Top;
						break;
					case "uxLeftDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Left;
						break;
					case "uxWidthDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Width;
						break;
					case "uxHeightDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Height;
						break;
					case "uxFontDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Font;
						break;
					case "uxDefaultValueDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].DefaultValue;
						break;
					case "uxVisibleDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Visible;
						break;
					case "uxEnableDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Enable;
						break;
					case "uxIsSummaryFieldDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].IsSummaryField;
						break;
					case "uxIsCommonDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].IsCommon;
						break;
					case "uxIsCodeDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].IsCode;
						break;
					case "uxIsLayoutDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].IsLayout;
						break;
					case "uxComponentIdDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].ComponentId;
						break;
					case "uxFormIdDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].FormId;
						break;
					case "uxFormTypeDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].FormType;
						break;
					case "uxStatusDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Status;
						break;
					case "uxDescriptionDataGridViewColumn":
						e.Value = FormControlList[e.RowIndex].Description;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxFormControlDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnFormControlDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxFormControlDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxControlIdDataGridViewColumn":
						FormControlList[e.RowIndex].ControlId = (System.Int32)e.Value;
						break;
					case "uxNameDataGridViewColumn":
						FormControlList[e.RowIndex].Name = (System.String)e.Value;
						break;
					case "uxControlTypeIdDataGridViewColumn":
						FormControlList[e.RowIndex].ControlTypeId = (System.Int32)e.Value;
						break;
					case "uxToolTipTextDataGridViewColumn":
						FormControlList[e.RowIndex].ToolTipText = (System.String)e.Value;
						break;
					case "uxBorderDataGridViewColumn":
						FormControlList[e.RowIndex].Border = (System.Boolean?)e.Value;
						break;
					case "uxTopDataGridViewColumn":
						FormControlList[e.RowIndex].Top = (System.Int32?)e.Value;
						break;
					case "uxLeftDataGridViewColumn":
						FormControlList[e.RowIndex].Left = (System.Int32?)e.Value;
						break;
					case "uxWidthDataGridViewColumn":
						FormControlList[e.RowIndex].Width = (System.Int32?)e.Value;
						break;
					case "uxHeightDataGridViewColumn":
						FormControlList[e.RowIndex].Height = (System.Int32?)e.Value;
						break;
					case "uxFontDataGridViewColumn":
						FormControlList[e.RowIndex].Font = (System.String)e.Value;
						break;
					case "uxDefaultValueDataGridViewColumn":
						FormControlList[e.RowIndex].DefaultValue = (System.String)e.Value;
						break;
					case "uxVisibleDataGridViewColumn":
						FormControlList[e.RowIndex].Visible = (System.Boolean?)e.Value;
						break;
					case "uxEnableDataGridViewColumn":
						FormControlList[e.RowIndex].Enable = (System.Boolean?)e.Value;
						break;
					case "uxIsSummaryFieldDataGridViewColumn":
						FormControlList[e.RowIndex].IsSummaryField = (System.Boolean?)e.Value;
						break;
					case "uxIsCommonDataGridViewColumn":
						FormControlList[e.RowIndex].IsCommon = (System.Boolean?)e.Value;
						break;
					case "uxIsCodeDataGridViewColumn":
						FormControlList[e.RowIndex].IsCode = (System.Boolean?)e.Value;
						break;
					case "uxIsLayoutDataGridViewColumn":
						FormControlList[e.RowIndex].IsLayout = (System.Boolean?)e.Value;
						break;
					case "uxComponentIdDataGridViewColumn":
						FormControlList[e.RowIndex].ComponentId = (System.Int32?)e.Value;
						break;
					case "uxFormIdDataGridViewColumn":
						FormControlList[e.RowIndex].FormId = (System.Int32)e.Value;
						break;
					case "uxFormTypeDataGridViewColumn":
						FormControlList[e.RowIndex].FormType = (System.Int32)e.Value;
						break;
					case "uxStatusDataGridViewColumn":
						FormControlList[e.RowIndex].Status = (System.Int32)e.Value;
						break;
					case "uxDescriptionDataGridViewColumn":
						FormControlList[e.RowIndex].Description = (System.String)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
